#include "stdafx.h"
#include "IDivide.h"
//OpenCV libs
#include "opencv2/core/core.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv/cv.h"

const char * const IDivide::FunctionNameIDivide = "Divide";

IDivide::IDivide(void) 
{
	_fnApi.SetFunctionName(IDivide::FunctionNameIDivide);
	_fnApi.SetFunctionDescription("divides a image on top");
									//inputs
	_fnApi.AddParamDef(new ProcParamDefString(0, "Image", "Sets the Image to be divided by. Make sure the dimensions are the same as that of the image you're using. Enter the path to the image", ProcParamDef::input, 0, 500 ));
									//outputs
	_fnApi.AddParamDef(new ProcParamDefInt(0, ProcParam::attribOutputParamNameResult, "0 is success", ProcParamDef::output, 0, 1));

	_fnApi.Validate();
}


IDivide::~IDivide(void)
{

}


bool IDivide::Process(ImageProcStep *step, bool DebugMode)
{	
	bool rc = false;
	if ((step != '\0') && (step->IsValid()))
	{
		
		ProcParamString *source = dynamic_cast<ProcParamString *>(step->GetInputs()->GetParam(0));	//Check the Param number

		if  (source != '\0')
		{
			cv::Mat output;
			cv::Mat input = cv::imread(step->GetIntermediateImagePathFilename());	
			cv::Mat input2 = cv::imread((std::string)source->GetValueStr());

			if (input.cols == input2.cols && input.rows == input2. rows)
			{
				cv::divide(input, input2, output);

				cv::imwrite(step->GetIntermediateImagePathFilename(), output);
				
				input.release();
				input2.release();
				output.release();
				rc = true;
			}
		}
	}
	return rc;
}

